<template>
	<view class="signIn">
		<view class="calendar_box"><zeng-calen :chooseDay="chooseDay" @changCurMonth="changCurMonth"></zeng-calen></view>
		<view class="area-title">签到规则</view>
		<view class="sign_in_tags">连续签到可获得额外积分奖励，最高可连续签到30天。连续签到30天后将重新开始计算连续签到天数</view>
		<button class="yellow_btn" @tap="signInNow">立即签到</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			actDay: [], //用户选择的日期
			chooseDay: [], //已被投标的数据
			curMonth: '',
			curDate: ''
			// changeMonth:''
		};
	},
	onLoad() {
		this.curMonth = this.$helper.formatDate(new Date(), 'yyyy-MM');
		this.curDate = this.$helper.formatDate(new Date(), 'yyyy-MM-dd');
		this.getSignCal();
	},
	methods: {
		signInNow() {
			this.$api.sign().then(res => {
				if (res.code == 1) {
					this.$helper.toast(res.msg);
					this.chooseDay.push(this.curDate);
				}
			});
		},
		getSignCal() {
			this.$api.getSignCal({ year_month: this.curMonth }).then(res => {
				console.log(res, '获取签到日历');
				this.chooseDay = res.data.lists.map(item => {
					return item.sign_date;
				});
			});
		},
		changCurMonth(year, month) {
			console.log(year, month, '切换l');
			let monthString = this.addZero(month);
			this.curMonth = year + '-' + monthString;
			this.getSignCal();
		},
		addZero(num) {
			if (num < 10) {
				return '0' + num;
			} else {
				return num.toString();
			}
		}
	}
};
</script>

<style lang="scss">
.signIn {
	min-height: 100vh;
	padding: 24rpx;
	background-color: #f9f9f9;
	.calendar_box {
		background: #ffffff;
		border-radius: 20rpx;
		margin-bottom: 50rpx;
	}
	.sign_in_tags {
		font-size: 28rpx;
		color: #666;
		margin-bottom: 70rpx;
		line-height: 40rpx;
	}
	.yellow_btn {
	}
}
</style>
